package ru.zombator.taskman.core.query;

import java.util.UUID;

/**
 * Пакет.
 * 
 * @see IPacket
 * @author nvamelichev
 *
 */
public class Packet implements IPacket {
	private static final long serialVersionUID = 1L;
	
	/**
	 * идентификатор запроса-ответа
	 */
	private UUID id;
	/**
	 * полезная нагрузка
	 */
	private byte[] bytes;
	
	public Packet(byte[] bytes) {
		this.id = UUID.randomUUID();
		this.bytes = bytes;
	}
	
	public Packet(byte[] bytes, UUID id) {
		this.id = id;
		this.bytes = bytes;
	}

	@Override
	public byte[] bytes() {
		return bytes;
	}

	@Override
	public UUID requestId() {
		return id;
	}

	@Override
	public int payloadSize() {
		return bytes.length;
	}
	
	@Override
	public int headerSize() {
		return 4 /*payloadSize*/ + 16 /*uuid*/;
	}
}
